<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit rsa package test</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>

<script language="JavaScript" type="text/javascript" src="../jsrsasign-rsa-min.js"></script>

<script type="text/javascript">
$(document).ready(function(){

var Z1PRVP5HEX = "3082013a020100024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001024078bbc54c646795e9a623cb0f912c7f9f6861711560e57bade21ded2f7d9579f86272fab9e71ab27282c2760c404dae6ac8a3ab852cf6bcd562f9aff8247a264d022100fe9bd450866b3255614fde976a76ac0b1d5830dda64f5359b946d8512bc1239f022100e9ab680f5f05dbb0f4311b0e6f4368f4874a1238979d8bc600c35c6f20707c07022100d549cb698dc17d4fe30e5a84f3ade860033c1eeb7f67d286465c9fd817d45b3702201849b4bb44493b989d092da2c675df46eb790b83ce5e95d4b2e79b88017b2fa902207d261a96256d49b020cb1d587ecde127e093a4d2b34cdbff171f34125b5857a9";

var Z1PRVP8HEX = "30820154020100300d06092a864886f70d01010105000482013e3082013a020100024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001024078bbc54c646795e9a623cb0f912c7f9f6861711560e57bade21ded2f7d9579f86272fab9e71ab27282c2760c404dae6ac8a3ab852cf6bcd562f9aff8247a264d022100fe9bd450866b3255614fde976a76ac0b1d5830dda64f5359b946d8512bc1239f022100e9ab680f5f05dbb0f4311b0e6f4368f4874a1238979d8bc600c35c6f20707c07022100d549cb698dc17d4fe30e5a84f3ade860033c1eeb7f67d286465c9fd817d45b3702201849b4bb44493b989d092da2c675df46eb790b83ce5e95d4b2e79b88017b2fa902207d261a96256d49b020cb1d587ecde127e093a4d2b34cdbff171f34125b5857a9"; // z1.prv.p8p.der

var Z1PUBP8HEX = "305c300d06092a864886f70d0101010500034b003048024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001"; // z1.pub.p8.der

var Z1CERTHEX = "308201753082011fa003020102020105300d06092a864886f70d0101050500301a310b3009060355040613025553310b3009060355040a0c026131301e170d3133303530343033343134315a170d3233303530343033343134315a301a310b3009060355040613025553310b3009060355040a0c026131305c300d06092a864886f70d0101010500034b003048024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001a350304e301d0603551d0e04160414c5473ee200c8e7ad7003dff5420b8cddf4c20e15301f0603551d23041830168014c5473ee200c8e7ad7003dff5420b8cddf4c20e15300c0603551d13040530030101ff300d06092a864886f70d0101050500034100b2f693af4b8f03987c35efdd35c950014652ab68f8da230892cfd3c7ce7cd059cbe280232d06b2b354ff7b91562a9bb86a809c7f64145c0742338016b01ef174"; // z1.der

var Z1N = new BigInteger("00e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd59", 16);
var Z1E = new BigInteger("010001", 16);
var Z1D = new BigInteger("78bbc54c646795e9a623cb0f912c7f9f6861711560e57bade21ded2f7d9579f86272fab9e71ab27282c2760c404dae6ac8a3ab852cf6bcd562f9aff8247a264d", 16);
var Z1P = new BigInteger("00fe9bd450866b3255614fde976a76ac0b1d5830dda64f5359b946d8512bc1239f", 16);
var Z1Q = new BigInteger("00e9ab680f5f05dbb0f4311b0e6f4368f4874a1238979d8bc600c35c6f20707c07", 16);
var Z1DP = new BigInteger("00d549cb698dc17d4fe30e5a84f3ade860033c1eeb7f67d286465c9fd817d45b37", 16);
var Z1DQ = new BigInteger("1849b4bb44493b989d092da2c675df46eb790b83ce5e95d4b2e79b88017b2fa9", 16);
var Z1CO = new BigInteger("7d261a96256d49b020cb1d587ecde127e093a4d2b34cdbff171f34125b5857a9", 16);

// sign "aaa" with z1prv and SHA1
var Z1SIG1AAA = "d764dcacb137f2e92d9b4b73494995e16a4dae4dc5b27ecde744c9a1ecaaef9c99041544eae2108dca6559ae79d2fb3d87fa2b87699efa6dc8f3d0d2672c3b07";

test("RSAKey.readPKCS8PrvHex", function() {
  var key = new RSAKey();
  key.readPKCS8PrvKeyHex(Z1PRVP8HEX);
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(Z1N.compareTo(key.n), 0, "N");
  equal(key.e, 65537, "E");
  equal(Z1D.compareTo(key.d), 0, "D");
  equal(Z1P.compareTo(key.p), 0, "P");
  equal(Z1Q.compareTo(key.q), 0, "Q");
  equal(Z1DP.compareTo(key.dmp1), 0, "DP");
  equal(Z1DQ.compareTo(key.dmq1), 0, "DQ");
  equal(Z1CO.compareTo(key.coeff), 0, "CO");
});

test("RSAKey.readPKCS8PubKeyHex", function() {
  var key = new RSAKey();
  key.readPKCS8PubKeyHex(Z1PUBP8HEX);
  equal(key.isPublic, true, "isPublic");
  equal(key.isPrivate, false, "isPrivate");
  equal(Z1N.compareTo(key.n), 0, "N");
  equal(key.e, 65537, "E");
});

test("RSAKey.signString", function() {
  var key = new RSAKey();
  key.readPKCS8PrvKeyHex(Z1PRVP8HEX);
  var hSig = key.sign("aaa", "sha1");
  equal(hSig, Z1SIG1AAA, "sign aaa with z1prv and SHA1");
});

test("RSAKey.verifyString", function() {
  var key = new RSAKey();
  key.readPKCS8PubKeyHex(Z1PUBP8HEX);
  equal(key.verify("aaa", Z1SIG1AAA), true, "verify sig with aaa");
});

});
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<p>
<a href="../">TOP</a> | 
<a href="index.html">TEST INDEX</a> | 
<a href="qunit-do-package-rsa.html">package(rsa)</a> | 
<a href="qunit-do-package-jwths.html">package(jwths)</a> | 
<a href="qunit-do-jws-sign.html">asynmetric key(RS/PS/ES) sign/verify</a> | 
<a href="qunit-do-jws-sign-hs.html">Hmac(HS) sign/verify</a> | 
<a href="qunit-do-jws-sign-slow.html">sign/verify slow</a> | 
<a href="qunit-do-jws-intdate.html">IntDate</a> | 
</p>
</body>
</html>

